<template>
  <div class="cesium-tool"></div>
</template>

<script lang="ts" setup>
import { useStageStore } from '@/store/stage';

defineOptions({
  name: 'SelectTool',
});

const stageStore = useStageStore();

onMounted(() => {
  const { cimInstance } = window;
  cimInstance.api.addPickerEventListener('mouse_leftclick', stageClickEventHandler);
});

/**
 * 场景点击回调
 * @param startPositionPicked - 点击场景所拾取到的对象（从clickAction.position获取）
 * @param endPositionPicked - 点击场景所拾取到的对象（从clickAction.endPosition获取）
 * @param clickAction - cesium场景中setInputAction默认原始的callback的参数
 * @param info - {name:对象的name,id:对象的id,layerType:图层类型,layerName:图层的名字}
 * @returns
 */
const stageClickEventHandler = (
  startPositionPicked: any,
  endPositionPicked: any,
  clickAction: any,
  info: any
) => {
  stageStore.layerId = info.id || '';
};
</script>

<style lang="less" scoped>
.cesium-tool {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
}
</style>
